/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.persistence.connection;

import java.util.*;
import java.sql.*;

import org.telosys.common.logger.TelosysClassLogger;

/**
 * 
 * Factory designed to create stand-alone connections <br>
 * ( connections that doesn't belong to a pool )
 * 
 * This class is a "ConnectionProvider"
 * 
 * @author Laurent GUERIN
 *  
 */

/* package */ class ConnectionProviderSingle extends ConnectionProviderAbstract
{
    //-----------------------------------------------------------------------------
    private static final TelosysClassLogger logger = new TelosysClassLogger(ConnectionProviderSingle.class);
    
    private void trace(String msg) {
    	logger.trace(msg);
    }
//    private void error(String msg) {
//    	logger.error(msg);
//    }
    
    //-----------------------------------------------------------------------------
    /**
     * Constructor
     * @param sDriver the JDBC driver to use
     * @param sUrl the JDBC URL 
     * @param prop the connection properties
     * @param iIsolationLevel the "isolation level"
     */
    //public ConnectionProviderSingle(String sName, String sDriver, String sUrl, Properties prop, int iIsolationLevel)
    public ConnectionProviderSingle( String sDriver, String sUrl, Properties prop, int iIsolationLevel)
    {
        //super(sName, sDriver, sUrl, prop, iIsolationLevel);
        super( sDriver, sUrl, prop, iIsolationLevel);
        trace("Constructor...");
    }

    //-----------------------------------------------------------------------------
    /* (non-Javadoc)
     * @see org.objectweb.telosys.dal.sql.SqlConnectionProvider#getConnection()
     */
    public synchronized Connection getConnection() throws Exception
    {
        trace("getConnection()");
        Connection stdCon = createStandardJdbcConnection();
        return new SqlConnection(stdCon);
    }

    //-----------------------------------------------------------------------------
    /* (non-Javadoc)
     * @see org.objectweb.telosys.dal.sql.SqlConnectionProvider#isPool()
     */
    public boolean isPool()
    {
        return false; // No this connection provider is not a pool
    }
    
//    //-----------------------------------------------------------------------------
//    /* (non-Javadoc)
//     * @see org.telosys.persistence.connection.ConnectionProvider#getInitialPoolSize()
//     */
//    public int getInitialPoolSize()
//    {
//        return 0 ;
//    }
//    
//    //-----------------------------------------------------------------------------
//	/* (non-Javadoc)
//	 * @see org.telosys.persistence.connection.ConnectionProvider#getPoolSize()
//	 */
//	public int getCurrentPoolSize() {
//        return 0 ;
//	}
    public PoolStatus getPoolStatus() 
    {
    	return new PoolStatus( 0, 0, 0, 0, getTypeName() );
    }


    //-----------------------------------------------------------------------------
    /* (non-Javadoc)
     * @see org.objectweb.telosys.dal.sql.ConnectionProvider#getType()
     */
    public int getType()
    {
        return ConnectionProvider.SINGLE ;  // This connection provider is a "FACTORY"
    }
    
    //-----------------------------------------------------------------------------
    /* (non-Javadoc)
     * @see org.telosys.persistence.connection.ConnectionProvider#getTypeAsString()
     */
    public String getTypeName()
    {
        return "Telosys Single Connection Provider" ;
    }
    

}